package com.LFLWZ.controller;


import com.LFLWZ.beans.Dto.Dto;
import com.LFLWZ.beans.POJO.ScandalUser;
import com.LFLWZ.service.ScandalUserService;
import com.LFLWZ.utils.DtoUtil;
import com.LFLWZ.utils.EmptyUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 个人模块
 */
@RestController
public class UserController {

    @Reference
    private ScandalUserService scandalUserService;

    @PostMapping("login")
    public Dto login(@RequestBody ScandalUser scandalUser){
        Dto dto=new Dto();
        if (scandalUser.getName()==null||("").equals(scandalUser.getName())){
            dto= DtoUtil.returnError(4001,"用户名不能为空");
        }
        if(scandalUser.getPassword()==null||("").equals(scandalUser.getPassword())){
            dto=DtoUtil.returnError(4001,"用户密码不能为空");
        }
        List<ScandalUser> list=scandalUserService.queryAll(scandalUser);
        if (EmptyUtils.isEmpty(list)){
            dto=DtoUtil.returnError(4002,"用户名账号密码不正确");
        }else {
            dto=DtoUtil.returnSuccessData(list.get(0));
        }
        System.out.println(list.get(0).getName());
        return dto;
    }
}
